package com.JackTang.demo;

import javafx.application.Application;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Jack Tang
 * @description
 * @create 2023-05-05 17:01
 */
// 演示 application 保存作用域 demo05 和 demo06
@WebServlet("/demo05")
public class Demo05Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1.向application 保存作用域
        // ServletContext: Servlet上下文
        ServletContext application = req.getServletContext();
        application.setAttribute("uname","lida");
        // 2.客户端重定向
        resp.sendRedirect("demo06");

        // 3.服务器端转发
//        req.getRequestDispatcher("demo04").forward(req,resp);
    }
}